package com.psp.sp.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.northend.util.AppTextUtil;
import com.psp.sp.controller.res.bean.ROrderDetailBean;
import com.psp.sp.controller.res.bean.ROrderListBean;
import com.psp.sp.service.OrderService;
import com.psp.sp.service.exception.ServiceException;

@Service
public class OrderServiceImpl implements OrderService {

	@Override
	public ROrderDetailBean getDetail(String uid, String oid) {
		ROrderDetailBean result = new ROrderDetailBean();
		result.setOid(AppTextUtil.getPrimaryKey());
		result.setOrderNo(AppTextUtil.getOrderNo(""));
		result.setCreateDate(System.currentTimeMillis());
		result.setNum(1);
		result.setOrderPrice(699.0);
		result.setState(new Random().nextInt(8) + 1);
		result.setBImg("http://pic.58pic.com/58pic/14/00/69/66858PICNfJ_1024.jpg");
		result.setBName("公司注册");
		result.setBuyerName("张三");
		result.setBuyerPhone("133333333");
		return result;
	}

	@Override
	public PageResult<ROrderListBean> getList(int page, int pageSize, String uid, int state) {
		PageResult<ROrderListBean> result = new PageResult<ROrderListBean>();

		// TODO 根据订单 state 状态 查询
		List<ROrderListBean> list = new ArrayList<>();

		for (int i = 0; i < 40; i++) {
			ROrderListBean bean = new ROrderListBean();

			bean.setOid(AppTextUtil.getPrimaryKey());
			bean.setOrderNo(AppTextUtil.getOrderNo(""));
			bean.setCreateDate(System.currentTimeMillis());
			bean.setNum(1);
			bean.setOrderPrice(699.0);
			bean.setState(new Random().nextInt(8) + 1);
			bean.setBImg("http://pic.58pic.com/58pic/14/00/69/66858PICNfJ_1024.jpg");
			bean.setBName("公司注册");
			bean.setBuyerName("张三");
			bean.setBuyerPhone("133333333");
			list.add(bean);
		}

		result.setCount(40);
		result.setData(list);
		return result;
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public boolean receive(String uid, String oid) throws ServiceException {
		boolean flag = false;

		return true;
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public boolean refuse(String uid, String oid) throws ServiceException {
		return false;
	}

}
